package cn.net.comsys.vpn.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.net.comsys.vpn.web.util.DataBase;

/**
 * @author JiF
 * @version 创建时间：2011-4-21 下午02:34:43 E-Mail:liaojifeng@163.com 类说明：
 * 
 * 
 * 
 */
public class VpnLoginProxy extends HttpServlet {
	private VpnLoginService vls=null;
	private String username;
	private String password;
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
			
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
			username=req.getParameter("username");
			password=req.getParameter("password");
			if (vls==null){
				vls=new VpnLoginService();
			}
			resp.setCharacterEncoding("UTF-8");
			if (username==null || password==null || password.length()<3 || username.length()<3){
				resp.getWriter().write("非法用户名/密码");
				resp.getWriter().flush();
				resp.getWriter().close();
				return;
			}
			try {
				vls.certAuther(username, password);
				req.getSession().setAttribute("username", username);
				req.getSession().setAttribute("password", password);
				
				resp.getWriter().write("VPNcertAuther_SUCCESS");
				resp.sendRedirect("UCIT_SSL_VPN.jsp");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
				resp.getWriter().write(e.getMessage());
			}
			resp.getWriter().flush();
			resp.getWriter().close();
			
	}

}
